<template>
	<view class="shopping_address">
		<Navbar>我的地址</Navbar>
		<scroll-view scroll-y class="scroll_view">
			<view class="content">
				<view class="title">
					<view>
						<image :src="`${baseImageUrl}/common/zw.png`"></image>
						<text>地址信息</text>
						<image :src="`${baseImageUrl}/common/zw.png`"></image>
					</view>
				</view>
				<view class="item">
					<view class="key">姓名</view>
					<input type="text" placeholder="请输入姓名" v-model="name" class="input">
				</view>
				<view class="item">
					<view class="key">电话号码</view>
					<input type="text" placeholder="请输入电话号码" v-model="phone" class="input">
				</view>
				<view class="item" @click="show=true">
					<view class="key">省市区</view>
					<view class="address">
						<uni-data-picker :localdata="columns" popup-title="请选择地址" :map="{text:'shortname',value:'id'}"
							:clear-icon="false" v-model="value" @change="onchange">
						</uni-data-picker>
					</view>
				</view>
				<view class="item">
					<view class="key">详细地址</view>
					<textarea type="text" placeholder="请输入详细地址" v-model="address" class="textarea" />
				</view>
				<view class="btn" @click="submit">确认</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		regionAll,
		shopUseraddressGet,
		shopUseraddressSet
	} from '@/request/api.js';
	export default {
		data() {
			return {
				name: "",
				phone: "",
				province_id: "",
				city_id: "",
				area_id: "",
				address: "",

				value: 0,
				columns: [],
			}
		},
		async onLoad() {
			this.getProvince();

			let {
				address
			} = await shopUseraddressGet();

			this.name = address.name;
			this.phone = address.phone;
			this.province_id = address.province_id;
			this.city_id = address.city_id;
			this.area_id = address.area_id;
			this.address = address.address;
		},
		methods: {
			async getProvince() {
				let res = await regionAll();
				this.value = Number(`${this.area_id}`);
				this.columns = res;
			},
			onchange(e) {
				const value = e.detail.value;
				this.province_id = value[0].value;
				this.city_id = value[1].value;
				this.area_id = value[2].value;
			},
			async submit() {
				await shopUseraddressSet({
					name: this.name,
					phone: this.phone,
					province_id: this.province_id,
					city_id: this.city_id,
					area_id: this.area_id,
					address: this.address
				});
				this.$u.toast("操作成功");
			}
		}
	}
</script>

<style scoped lang="scss">
	.shopping_address {
		height: 100vh;
		background: #29170D;

		.scroll_view {
			height: calc(100vh - #{$navbarHeight});
			padding-top: 48rpx;
			box-sizing: border-box;

			.content {
				width: 100%;
				height: 1000rpx;
				padding: 32rpx 75rpx 40rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/bg/750_800.png) no-repeat;
				background-size: 100% 100%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;

				.title {
					display: flex;
					justify-content: center;
					align-items: center;

					view {
						height: 30rpx;
						display: flex;
						align-items: center;

						image {
							width: 30rpx;
							height: 30rpx;
						}

						text {
							color: #494338;
							font-size: 42rpx;
							font-weight: 400;
							font-family: LiSu;
							margin: 0 10rpx;
						}
					}
				}

				.item {
					width: 100%;

					.key {
						color: #494338;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
						margin-bottom: 20rpx;
					}

					.input {
						width: 100%;
						height: 80rpx;
						border-radius: 10rpx;
						padding-left: 30rpx;
						padding-right: 20rpx;
						box-sizing: border-box;
						box-shadow: 2rpx -1px 10rpx 0px rgba(3, 0, 0, 0.2);
						background: #C0B5B6;
						display: flex;
						justify-content: space-between;
						align-items: center;
					}

					.address {
						width: 100%;
						height: 80rpx;
						border-radius: 10rpx;
						padding-left: 30rpx;
						padding-right: 20rpx;
						box-sizing: border-box;
						box-shadow: 2rpx -1px 10rpx 0px rgba(3, 0, 0, 0.2);
						background: #C0B5B6;
						overflow: hidden;
						display: flex;
						align-items: center;

						/deep/ .input-value {
							border: none;
							padding: 0;

							.selected-area {
								color: #808080;
								font-size: 28rpx;
								font-weight: 400;
								font-family: SimSun;
							}
						}
					}

					.textarea {
						width: 100%;
						height: 200rpx;
						border-radius: 10rpx;
						padding: 30rpx;
						box-sizing: border-box;
						box-shadow: 2rpx -1px 10rpx 0px rgba(3, 0, 0, 0.2);
						background: #C0B5B6;
					}

					image {
						width: 34rpx;
						height: 34rpx;
					}
				}

				.btn {
					width: 204rpx;
					height: 74rpx;
					line-height: 74rpx;
					text-align: center;
					color: #FFFFFF;
					font-size: 30rpx;
					font-weight: 400;
					font-family: SimSun;
					background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}
	}
</style>